'//DotNetNuke - http://www.dotnetnuke.com
'// Copyright (c) 2002-2010
'// by DotNetNuke Corporation
'//
'// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
'// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
'// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
'// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'//
'// The above copyright notice and this permission notice shall be included in all copies or substantial portions
'// of the Software.
'//
'// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
'// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
'// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
'// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
'// DEALINGS IN THE SOFTWARE.

Imports DotNetNuke.Modules.dnnsimplearticle.Components
Imports DotNetNuke
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Entities.Modules



    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' The Editdnnsimplearticle class is used to manage content
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Partial Class Edit
        Inherits dnnsimplearticleModuleBase

#Region "Private Members"

#End Region

#Region "Event Handlers"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Page_Load runs when the control is loaded
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
            'Implement your edit logic for your module
            If Not Page.IsPostBack Then

                Dim article = New Article()
                tsTerms.Terms = article.Terms
                article = ArticleController.GetArticle(ArticleId)

                tsTerms.PortalId = PortalId

                If article IsNot Nothing Then
                    txtTitle.Text = article.Title
                    txtDescription.Text = article.Description
                    txtBody.Text = article.Body
                    tsTerms.Terms = article.Terms
                End If

                tsTerms.DataBind()
            End If


            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region

    Protected Sub LbSaveClick(ByVal sender As Object, ByVal e As EventArgs) Handles lbSave.Click
        Dim a As Article
        If ArticleId > 0 Then
            a = ArticleController.GetArticle(ArticleId)
            a.Title = txtTitle.Text.Trim()
            a.Description = txtDescription.Text.Trim()
            a.Body = txtBody.Text
            a.LastModifiedOnDate = DateTime.Now
            a.LastModifiedByUserId = UserInfo.UserID

            a.ModuleId = ModuleId
        Else
            a = New Article() With { _
             .Title = txtTitle.Text.Trim(), _
             .Description = txtDescription.Text.Trim(), _
             .Body = txtBody.Text, _
             .CreatedOnDate = DateTime.Now, _
             .CreatedByUserId = UserInfo.UserID, _
             .LastModifiedOnDate = DateTime.Now, _
             .LastModifiedByUserId = UserInfo.UserID, _
             .ModuleId = ModuleId _
            }
        End If

        If tsTerms.Terms IsNot Nothing Then
            a.Terms.Clear()
            a.Terms.AddRange(tsTerms.Terms)
        End If
        a.Save(TabId)
        Response.Redirect(Common.Globals.NavigateURL(TabId))

    End Sub

    Protected Sub LbCancelClick(ByVal sender As Object, ByVal e As EventArgs) Handles lbCancel.Click
        Response.Redirect(Common.Globals.NavigateURL(TabId))
    End Sub
End Class

